package msgcomm.transceivers;

import java.rmi.NoSuchObjectException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.LinkedList;
import java.util.Queue;

import msgcomm.Hooks;
import msgcomm.RmiReceiver;
import msgcomm.messages.Message;


public class RmiReliableCausalOrderingMulticast extends ReliableCausalOrderingMulticast implements RmiReceiver {

	protected RmiReliableCausalOrderingMulticast(String name, Queue<Message> msgQueue, Hooks reqList) {
		super(name, msgQueue, reqList);
		// export
		try {
			UnicastRemoteObject.exportObject((RmiReceiver)this, 0);
		} catch (RemoteException e) {
			// unexport	
			unexport();
		}
	}
	
	protected RmiReliableCausalOrderingMulticast(String name, Queue<Message> msgQueue) {
		this(name, msgQueue, null);
	}
	
	public RmiReliableCausalOrderingMulticast(String name) {
		this(name, new LinkedList<Message>(), null);
	}
	
	public RmiReliableCausalOrderingMulticast(String name, Hooks reqList) {
		this(name, new LinkedList<Message>(), reqList);
	}
	
	/**
     * Esegue l'operazione di unexport di questo transceiver.
     */
	public void unexport(){
		
		log.print("Rimuovo l'esportazione dell'oggetto RmiReceiver");
		try {
			UnicastRemoteObject.unexportObject((RmiReceiver)this, true);
		} catch (NoSuchObjectException e) {
			log.printErr("l'oggetto remoto non esiste piu'");
			e.printStackTrace(log.getErrorPrintStream());
		}
		
	}
	
}
